package demo523;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.Scanner;
public class LoginDemo {
    public static <CharacterIteratorWrapper> void main(String[] args) throws ClassNotFoundException, SQLException {
        Connection connection = SqlConnection.getCon();
        Scanner scanner = new Scanner(System.in);
        System.out.println("用户名：");
        String username = scanner.next();
        System.out.println("密码是：");
        String passwors = scanner.next();
        String sql = "select*from users  where username=? and password=?";
        PreparedStatement preparedStatement = connection.prepareStatement(sql);
        preparedStatement.setString(1,username);
        preparedStatement.setString(2,passwors);
        ResultSet resultSet = preparedStatement.executeQuery();

        if (resultSet.next()){
            String name = resultSet.getString("username");
            String password = resultSet.getString("password");
            System.out.println("用户名："+name);
            System.out.println("密码是:"+password);
            System.out.println("成功");
        }
        else {
            System.out.println("你的用户名或者密码错误");
        }
    }
}
